# -*- coding: utf-8 -*-
"""
@Time ： 2020/11/6 20:03
@Auth ： Mr. William 1052949192
@Company ：特斯汀学院 @testingedu.com.cn
@Function ：参数化
"""
import os
import traceback

import pytest


def sum(x, y):
    """
    求x+y的值
    :param x: 第一个加数
    :param y: 第二个加数
    :return: 相加后的结果
    """
    return x + y


# # 普通测试
# def as_equal(a, b):
#     if a == b:
#         print('Pass')
#     else:
#         print('Fail')
#
#
# z = sum(1, 1)
# as_equal(z, 2)
# z = sum(1, -1)
# as_equal(z, 0)
# z = sum(1, 1.1)
# as_equal(z, 2.1)
# # 有可能报错的代码段进行错误处理：异常捕获
# try:
#     z = sum(1, '1')
#     as_equal(z, '11')
# except Exception as e:
#     """
#     except里面能不能再写有可能报错的代码？不能
#     """
#     print(e.__str__())
#     # print(traceback.format_exc())
#     print('Fail')

p = [
    [1, 1, 2],
    [1, -1, 0],
    [1, 1.1, 2.1],
    [1, '1', None]
]


@pytest.mark.parametrize('sump', p)
def test_sum(sump):
    """
    测试用例
    :return:
    """
    print(sump)
    if sump[2] is not None:
        z = sum(sump[0], sump[1])
        assert z == sump[2]
    else:
        try:
            sum(sump[0], sump[1])
            assert False
        except:
            assert True


if __name__ == '__main__':
    pytest.main(['-s', 'example03.py', '--alluredir', './temp'])
    # 执行命令行
    os.system('allure generate ./temp -o ./report --clean')
